package com.huluobo.a2111douyindemo.video;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.google.gson.Gson;
import com.huluobo.mvvm_base.mvvm.base.viewmodel.BaseViewModel;
import com.huluobo.mvvm_base.mvvm.bean.CommentBeanResult;
import com.huluobo.mvvm_base.mvvm.bean.FollowBeanResult;
import com.huluobo.mvvm_base.mvvm.bean.LikeVideoBeanResult;
import com.huluobo.mvvm_base.mvvm.bean.VideoBeanResult;
import com.huluobo.mvvm_base.mvvm.net.Const;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * Created by LC on 2024/2/28.
 */
public class VideoViewModel extends BaseViewModel<VideoRepo> {

    MutableLiveData<VideoBeanResult> success = new MutableLiveData<>();
    MutableLiveData<String> failed = new MutableLiveData<>();

    MutableLiveData<LikeVideoBeanResult> likeSuccess = new MutableLiveData<>();

    MutableLiveData<String> likeFailed = new MutableLiveData<>();

    MutableLiveData<LikeVideoBeanResult> noLikeSuccess = new MutableLiveData<>();

    MutableLiveData<String> noLikeFailed = new MutableLiveData<>();

    MutableLiveData<FollowBeanResult> followSuccess = new MutableLiveData<>();

    MutableLiveData<String> followFailed = new MutableLiveData<>();

    MutableLiveData<CommentBeanResult> getCommentSuccess = new MutableLiveData<>();

    MutableLiveData<String> getCommentFailed = new MutableLiveData<>();

    MutableLiveData<CommentBeanResult> sendCommentSuccess = new MutableLiveData<>();

    MutableLiveData<String> sendCommentFailed = new MutableLiveData<>();

    public void getVideoList(int currentPage, int pageSize) {
        repo.getVideoList(currentPage, pageSize, success, failed);
    }

    public void likeVideo(int videoId) {
        repo.likeVideo(videoId, likeSuccess, likeFailed);
    }

    public void noLikeVideo(int videoId) {
        repo.noLikeVideo(videoId, noLikeSuccess, noLikeFailed);
    }

    public void followAuth(String authName) {
        Map<String, String> map = new HashMap<>();
        map.put(Const.PARAM_AUTH_NAME, authName);
        String json = new Gson().toJson(map);
        RequestBody body = RequestBody.create(MediaType.parse(Const.MEDIA_PARSE), json);
        repo.followAuth(body, followSuccess, followFailed);
    }

    public void getCommentByVideoId(int videoId) {
        repo.getCommentByVideoId(videoId, getCommentSuccess, getCommentFailed);
    }

    public void sendComment(String msg, int videoId) {
        Map<String, Object> map = new HashMap<>();
        map.put(Const.PARAM_MSG, msg);
        map.put(Const.PARAM_VIDEO_ID, videoId);

        String json = new Gson().toJson(map);
        RequestBody body = RequestBody.create(MediaType.parse(Const.MEDIA_PARSE), json);
        repo.sendComment(body, sendCommentSuccess, sendCommentFailed);
    }

    public VideoViewModel(@NonNull Application application) {
        super(application);
    }

    @Override
    protected VideoRepo createRepo() {
        return new VideoRepo();
    }
}
